package de.tabuma.sso.shopping;

import java.util.*;
import java.util.logging.*;
import de.tabuma.shopping.entity.*;
import de.tabuma.sso.constants;

/**
 * @author $Author: alefen $
 * @version $Revision: 1.1.1.1.2.1.2.1 $
 * @since $Date: 2010/01/13 10:23:10 $
 */
public class ShoppingFacade implements de.tabuma.shopping.logik.LicensePackageFacade {

    public static double getPrice(int licenseCount, double licensePrice, double asset) {
        double price = (licenseCount*licensePrice*(1+asset));
        price += 0.35;
        double newprice = price;
        for(int i=0;i<10;i++) {
            newprice = newprice * 0.039 + newprice * de.tabuma.shopping.constants.vat/100;
            price += newprice;
        }

        return price;
    }

    private License simpleSSOLicense100 = new License(1, 100, constants.SSO_SOAP_LICENSE_TYP ,0);
    private License simpleSSOLicense1000 = new License(2, 1000, constants.SSO_SOAP_LICENSE_TYP ,0);
    private License simpleSSOLicense5000 = new License(3, 5000, constants.SSO_SOAP_LICENSE_TYP ,0);

    private License[] simpleXFormCreationLicense1List = {simpleSSOLicense100};
    private License[] simpleXFormCreationLicense5List = {simpleSSOLicense1000};
    private License[] simpleXFormCreationLicense10List = {simpleSSOLicense5000};

    private LicensePackage currentLicensePackageList[] = {
        new LicensePackage(new Long(1), "SOAP License 100","License for calling a sso webservice 100 times.", getPrice(100,0.01,1.5) , simpleXFormCreationLicense1List ),
        new LicensePackage(new Long(2), "SOAP License 1000","License for calling a sso webservice 1000 times.", getPrice(1000,0.01,1) , simpleXFormCreationLicense5List),
        new LicensePackage(new Long(3), "SOAP License 5000","License for calling a sso webservice 5000 times.", getPrice(5000,0.01,0.5), simpleXFormCreationLicense10List),
    };

    private static final LicensePackage oldLicensePackageList[] = {};

    public List<LicensePackage> getCurrentLicensePackageList() {
        ArrayList<LicensePackage> list = new ArrayList<LicensePackage>();
        for(int i=0;i<currentLicensePackageList.length;i++) {
            list.add(currentLicensePackageList[i]);
        }
        return list;
    }

    public List<LicensePackage> getOldLicensePackageList() {
        ArrayList<LicensePackage> list = new ArrayList<LicensePackage>();
        for(int i=0;i<oldLicensePackageList.length;i++) {
            list.add(oldLicensePackageList[i]);
        }
        return list;
    }

    public List<LicensePackage> getAllLicensePackageList() {
        ArrayList<LicensePackage> list = new ArrayList<LicensePackage>();
        list.addAll(getCurrentLicensePackageList());
        list.addAll(getOldLicensePackageList());
        return list;
    }

    public LicensePackage getLicensePackageWithID(int id) {
        for(int i=0;i<currentLicensePackageList.length;i++) {
            if(currentLicensePackageList[i].getId()==id) {
                return currentLicensePackageList[i];
            }
        }
        for(int i=0;i<oldLicensePackageList.length;i++) {
            if(oldLicensePackageList[i].getId()==id) {
                return oldLicensePackageList[i];
            }
        }
        return null;
    }
    
}
